from django.shortcuts import render
from rest_framework.views import APIView
from rest_framework.response import Response
from home.serializer import NavSweializer,BannerSerializer
from home.models import NavModel,BannerModel
from fuguangeduapi.utils import constants
from rest_framework.generics import ListAPIView,CreateAPIView
from fuguangeduapi.utils.views import CaCheListApiView
 # 头部导航
# class NavHeardViews(APIView):
#     def get(self,request):
#         navmodel = NavModel.objects.filter(is_show=True,is_deleted=False,position=constants.NAV_HEARD).order_by('-id')[:constants.NAV_HEARD_MAX_SIZE]
#         navser = NavSweializer(instance=navmodel,many=True)
#         return Response({"message":'导航菜单请求','data':navser.data})
class NavHeardListViews(CaCheListApiView):
    queryset = NavModel.objects.filter(is_show=True,is_deleted=False,position=constants.NAV_HEARD).order_by('-id')[:constants.NAV_HEARD_MAX_SIZE]
    serializer_class = NavSweializer


 # 底部导航
# class NavFooterViews(APIView):
#     def get(self,request):
#         navmodel = NavModel.objects.filter(is_show=True,is_deleted=False,position=constants.NAV_FOOTER).order_by('-id')[:constants.NAV_FOOTER_MAX_SIZE]
#         navser = NavSweializer(instance=navmodel,many=True)
#         return Response({"message":'导航菜单请求','data':navser.data})
class NavFooterListViews(CaCheListApiView):
    queryset = NavModel.objects.filter(is_show=True,is_deleted=False,position=constants.NAV_FOOTER).order_by('-id')[:constants.NAV_FOOTER_MAX_SIZE]
    serializer_class = NavSweializer


class BannerViews(CaCheListApiView,CreateAPIView):
    queryset = BannerModel.objects.filter(is_show=True,is_deleted=False).order_by('-id')[:constants.BANNER_MAX_SIZE]
    serializer_class = BannerSerializer